﻿using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Threading.Tasks;
using WMSmanagement.IBaseService.PurchasingManagement;
using WMSmanagement.IBaseService.PurchasingManagement.Dto;
using WMSmanagement.Model;

namespace WMSmanagement.Web.Controllers
{
    public class ProcurementController : Controller
    {
        private readonly IProcurementService _procurementService;
        public ProcurementController(IProcurementService procurementService)
        {
            _procurementService = procurementService;
        }
        public IActionResult Show()
        {
            return View();
        }
        public IActionResult Add()
        {
            return View();
        }
        public IActionResult Update()
        {
            return View();
        }
        public IActionResult ChangeProducts()
        {
            return View();
        }
        /// <summary>
        /// 获取采购列表
        /// </summary>
        /// <param name="procurementCode"></param>
        /// <param name="productCode"></param>
        /// <param name="productName"></param>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetProcurement(string procurementCode = "", string productCode = "", string productName = "", string state = "", int page = 1, int limit = 10)
        {
            var result = await _procurementService.GetProcurementAsync(procurementCode, productCode, productName, state, page, limit);
            return Ok(result);
        }
        /// <summary>
        /// 添加采购
        /// </summary>
        /// <param name="addProcurementDto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> AddProcurement(AddProcurementDto addProcurementDto)
        {
            int res = await _procurementService.AddProcurementAsync(addProcurementDto);
            return Ok(res);
        }
        /// <summary>
        /// 删除采购
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> DeleteProcurement(int id)
        {
            int res = await _procurementService.DeleteProcurementAsync(id);
            return Ok(res);
        }
        /// <summary>
        /// 修改采购
        /// </summary>
        /// <param name="procurementDto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> UpdateProcurement(UpdateProcurementDto updateProcurementDto)
        {
            int res = await _procurementService.UpdateProcurementAsync(updateProcurementDto);
            return Ok(res);
        }
        /// <summary>
        /// 产品列表
        /// </summary>
        /// <param name="productCode"></param>
        /// <param name="productName"></param>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetProducts(string productCode = "", string productName = "", int page = 1, int limit = 10)
        {
            var result = await _procurementService.GetProductsAsync(productCode, productName, page, limit);
            return Ok(result);
        }
    }
}
